#ifndef __LOGMANAGER_H
#define __LOGMANAGER_H
#include <string>
#include <vector>
#include <mutex>

class Log {
public:
    enum class LogType { 
        UserAction, DeviceAction, SystemError
     };

    Log(LogType logType, int userId, int deviceId, const std::string& content)
        : logType(logType), userId(userId), deviceId(deviceId), content(content) {}

    LogType getLogType() const { 
        return logType; 
    }

    int getUserId() const { 
        return userId; 
    }

    int getDeviceId() const { 
        return deviceId; 
    }

    const std::string& getContent() const {
         return content; 
        }

private:
    LogType logType;
    int userId;
    int deviceId;
    std::string content;
};

class LogManager {
public:
    LogManager();

    void logAction(Log::LogType logType, int userId, int deviceId, const std::string& content);

    void saveLogsToFile(const std::string& filename);

    std::vector<Log> getLogsByUser(int userId) const;

    std::vector<Log> getLogsByDevice(int deviceId) const;
    
private:
    std::vector<Log> logs;
    std::mutex logMutex; // 用于线程安全的日志写入
};


#endif
